package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;

abstract class zalh {
   WorksheetCollection a;
   LightCellsDataProvider b;
   zack c;
   private int j;
   private zbpx k;
   private zbvx l;
   private int m;
   int d;
   int e;
   HashMap f = new HashMap();
   ArrayList g = new ArrayList();
   ArrayList h = new ArrayList();
   long i;

   public zalh(zack var1, LightCellsDataProvider var2) {
      this.c = var1;
      this.a = var1.e.getWorksheets();
      this.b = var2;
      if (!zsu.a(this.a)) {
         this.j = this.a.getCount() - 1;
      } else {
         this.j = this.a.getCount() - 2;
      }

      this.k = this.a.g;
      this.d = this.k.d();
      this.l = this.a.B();
      this.e = this.l.getCount();
      this.i = this.k.c();
      this.m = var1.c - this.e;
   }

   public zafw a(Worksheet var1) {
      int var2 = var1.getIndex();
      return var2 <= this.j && this.b.startSheet(var2) ? new zgz(var1, this.b, this) : null;
   }

   public Style a(int var1) {
      if (var1 < 0) {
         return this.l.a(15);
      } else {
         return var1 < this.e ? this.l.a(var1) : (Style)this.h.get(var1 - this.e);
      }
   }

   public int a(Style var1) {
      if (var1.getName() != null) {
         return this.b(this.l.c(var1));
      } else {
         int var2;
         for(var2 = this.h.size() - 1; var2 > -1; --var2) {
            if (var1.c((Style)this.h.get(var2))) {
               return this.e + var2;
            }
         }

         var2 = this.l.a(var1);
         if (var2 > -1 && var2 < this.e) {
            return var2;
         } else {
            Style var3 = new Style(this.a);
            var3.copy(var1);
            return this.b(var3);
         }
      }
   }

   public int b(int var1) {
      if (var1 < this.e) {
         return var1;
      } else {
         Style var2 = this.l.a(var1);

         for(int var3 = this.h.size() - 1; var3 > -1; --var3) {
            if (var2.c((Style)this.h.get(var3))) {
               return this.e + var3;
            }
         }

         if (var2.h() >= this.e) {
            Style var6 = this.l.a(var2.h());
            boolean var4 = true;

            for(int var5 = this.h.size() - 1; var5 > -1; --var5) {
               if (var6.c((Style)this.h.get(var5))) {
                  var4 = false;
                  break;
               }
            }

            if (var4) {
               this.b(var6);
            }
         }

         return this.b(var2);
      }
   }

   private int b(Style var1) {
      int var2 = this.e + this.h.size();
      if (var2 >= this.m) {
         throw new CellsException(10, "You have used too many different styles.");
      } else {
         Font var3 = var1.q();
         if (var3 != null) {
            this.a.a(var3);
         }

         String var4 = var1.getCustom();
         if (var4 != null && !"".equals(var4)) {
            var1.d(this.a.d(var4));
         }

         this.a(var1, var2);
         com.aspose.cells.b.a.a.ze.a(this.h, (Object)var1);
         return var2;
      }
   }

   abstract void a(Style var1, int var2);

   public int a(String var1) {
      return this.a(var1, this.b.isGatherString());
   }

   public int a(String var1, boolean var2) {
      ++this.i;
      zayy var3 = (zayy)this.k.a().get(var1);
      if (var3 != null && var3.e < this.d) {
         return var3.e;
      } else {
         Object var4 = this.f.get(var1);
         if (var4 != null) {
            return (Integer)var4;
         } else {
            int var5 = this.d + this.g.size();
            if (var2) {
               this.f.put(var1, var5);
            }

            com.aspose.cells.b.a.a.ze.a(this.g, (Object)var1);
            return var5;
         }
      }
   }
}
